package com.zh.common.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * code is far away from bug with the animal protecting
 * ┏┓　　　┏┓
 * ┏┛┻━━━┛┻┓
 * ┃　　　　　　　┃
 * ┃　　　━　　　┃
 * ┃　┳┛　┗┳　┃
 * ┃　　　　　　　┃
 * ┃　　　┻　　　┃
 * ┃　　　　　　　┃
 * ┗━┓　　　┏━┛
 * 　　┃　　　┃神兽保佑
 * 　　┃　　　┃代码无BUG！
 * 　　┃　　　┗━━━┓
 * 　　┃　　　　　　　┣┓
 * 　　┃　　　　　　　┏┛
 * 　　┗┓┓┏━┳┓┏┛
 * 　　　┃┫┫　┃┫┫
 * 　　　┗┻┛　┗┻┛
 *
 * @Description: outh2信息类
 * @Author: Li.HuiNeng
 * @Create in: 2019-09-20 11:35
 * @Version: 1.0.1
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Oauth extends Model<Oauth> implements UserDetails {

    private static final long serialVersionUID = -7714532534644335395L;

    // 授权服务端点
    @ApiModelProperty(value = "客户端授权范围", name = "scope")
    private String scope;
    @ApiModelProperty(value = "客户端授权类型", name = "grantType")
    private String grantType;
    @ApiModelProperty(value = "请求头类型(一般情况下固定)", name = "headerKey", example = "Authorization")
    private String headerKey;
    @ApiModelProperty(value = "请求头值(由服务器client_id:client_secret组合经过base64编码形成的秘钥)", name = "HeaderValue", example = "Basic YWRtaW46MTIzNDU2")
    private String headerValue;

    // 自定义属性部分
    @ApiModelProperty(value = "主键", name = "id")
    private Long id;
    @ApiModelProperty(value = "编号", name = "userRoleNo", required = true)
    private String userRoleId;
    @ApiModelProperty(value = "角色类型0.超级管理员，1.机构类型，2.代理商类型，3.商户类型，4.账户类型", name = "typeId")
    private Integer typeId;
    @ApiModelProperty(value = "关联主键", name = "foreign_key_id")
    private Long foreignKeyId;
    @ApiModelProperty(value = "关联下级编号(本平台)", name = "foreignNo")
    @TableField(exist = false)
    private String foreignNo;
    @ApiModelProperty(value = "关联下级名称", name = "foreignName")
    @TableField(exist = false)
    private String foreignName;
    @ApiModelProperty(value = "真实姓名", name = "userTrueName")
    private String userTrueName;
    @ApiModelProperty(value = "菜单集", name = "menus")
    private List<ElecMenu> menus;


    // 默认字段
    @ApiModelProperty(value = "登陆账号", name = "userLoginName")
    private String userLoginName;
    @ApiModelProperty(value = "用户密码", name = "userPassword", required = true)
    private String userPassword;
    @ApiModelProperty(value = "权限集合", name = "authorities")
    private Collection<? extends GrantedAuthority> authorities;
    @ApiModelProperty(value = "账户是否未锁定true:未锁定", name = "isAccountNonLocked")
    private boolean isAccountNonLocked;
    @ApiModelProperty(value = "账户是否未过期true:未过期", name = "isAccountNonExpired")
    private boolean isAccountNonExpired;
    @ApiModelProperty(value = "证书是否未过期true:未过期", name = "isCredentialsNonExpired")
    private boolean isCredentialsNonExpired;
    @ApiModelProperty(value = "账户是否注销true:未注销", name = "isEnabled")
    private boolean isEnabled;
    @ApiModelProperty(value = "账号是否启用true:未启用", name = "isWait")
    private boolean isWait;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    @Override
    public String getPassword() {
        return this.userPassword;
    }

    @Override
    public String getUsername() {
        return this.userLoginName;
    }

    @Override
    public boolean isAccountNonExpired() {
        return this.isAccountNonExpired;
    }

    @Override
    public boolean isAccountNonLocked() {
        return this.isAccountNonLocked;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return this.isCredentialsNonExpired;
    }

    @Override
    public boolean isEnabled() {
        return this.isEnabled;
    }

    public Oauth() {
    }

    public Oauth(boolean isAccountNonLocked, boolean isAccountNonExpired, boolean isCredentialsNonExpired, boolean isEnabled, boolean isWait) {
        this.isAccountNonLocked = isAccountNonLocked;
        this.isAccountNonExpired = isAccountNonExpired;
        this.isCredentialsNonExpired = isCredentialsNonExpired;
        this.isEnabled = isEnabled;
        this.isWait = isWait;
    }

    public Oauth(String userRoleId, Integer typeId,
                 Long foreignKeyId, String foreignNo, String foreignName,
                 String userLoginName,String userPassword,
                 Collection<? extends GrantedAuthority> authorities,
                 boolean isAccountNonLocked, boolean isAccountNonExpired, boolean isCredentialsNonExpired, boolean isEnabled, boolean isWait) {
        this.userRoleId = userRoleId;
        this.typeId = typeId;
        this.foreignKeyId = foreignKeyId;
        this.foreignNo = foreignNo;
        this.foreignName = foreignName;
        this.userLoginName = userLoginName;
        this.userPassword = userPassword;
        this.authorities = authorities;
        this.isAccountNonLocked = isAccountNonLocked;
        this.isAccountNonExpired = isAccountNonExpired;
        this.isCredentialsNonExpired = isCredentialsNonExpired;
        this.isEnabled = isEnabled;
        this.isWait = isWait;
    }
}
